package util;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 *@ClassName: threadPool
 *@Description: 创建线程池
 *@Params:
 *@Return:
 *@Author xxw
 *@Date 2021/12/8
 */
public class ThreadUtils {
    // 规避资源耗尽的风险
    public ExecutorService creatThreadPool() {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("thread-%d").build();
        // LinkedBlockingDeque 设置无限大
        ExecutorService  executorService = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<Runnable>(Integer.MAX_VALUE), threadFactory, new ThreadPoolExecutor.AbortPolicy());
        return executorService;
    }
}
